Properties on intersections should be readonly only if all declarations are #45263
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #45122
This changes the behavior of readonly properties in intersection types to be writable if any of the definitions of the property are writable. Before, the property would only be writable if none of its definitions were readonly (same as for unions).
I've added a new test containing the two cases from the issue, as well as a case that verifies that the property is still readonly if all of the definitions are readonly. I also had to update the baseline for two existing tests:
tests/cases/conformance/types/intersection/intersectionTypeReadonly.ts
- contained a test for the mutable & readonly case, which I've updated to not expect an errortests/cases/compiler/mappedTypeRecursiveInference.ts
-lib.dom.d.ts
defines the type ofdocument.defaultView
as(WindowProxy & typeof globalThis) | null
. It turned out that some of the properties (such asnavigator
) onWindowProxy
are readonly, while the corresponding global declaration is not. This change makes those properties writable in the intersection type.It seems a little odd that properties defined as readonly on
Window
are considered writable on the global. I'm not sure if that is something that needs to be addressed here?